package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.enums.eMessageType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Author : Cxp
 * @Time : 2025-1-23
 * @Description : 使用旅行册随机卡牌包
 */

public class UserTravelBookRandomPack extends BaseUseGoods {

    public UserTravelBookRandomPack(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        UseGoodsResult result = new UseGoodsResult();
        Property reward = new Property();
        for (long i = 0; i < count; i++) {
            OpenGoodsBagResult openResult = GoodsBagMgr.getRandomGoods(goodsInfo.getGoodsId(), player, reward);
            reward.addProperty(openResult.getReward());
            if (openResult.getNotice() == 1) {
                WorldMessageMgr.worldNotify(player, eMessageType.OpenGoodsBagNotice.getValue(), player.getUserInfo().getCity(), player.getTitleId(),
                        player.getUserInfo().getNickName(), goodsInfo.getGoodsId(), PropertyHelper.parsePropertyToString(openResult.getReward()));
            }
        }
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Bag, eLogMoneyType.OpenGoodsBag);
        result.setReward(PropertyHelper.parsePropertyToString(reward));
        return result;
    }
}
